package com.kkb.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@WebFilter("/check")
public class CheckFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        String[] goods = req.getParameterValues("good");

        List<String> newGoods = Stream.of(goods).filter(item -> {
            return !item.equals("炸弹") && !item.equals("汽油");
        }).collect(Collectors.toList());

        System.out.println(newGoods);
        req.setAttribute("newGoods",newGoods);
        chain.doFilter(req,resp);
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
